<?php 
class cart 
{ 
   
    function addItem($data) 
    { 
	
	$_SESSION['cart'][$data['Product_id']] = $data;
	
 /*       if(is_array($data)&&!empty($data)) 
        { 
            foreach($data as $key=>$val) 
            { 
               
                if($this->_isExists($key)) 
                { 
                    $_SESSION['cart'][$key]["count"] += floatval($val['price'])*intval($val['num']); 
                    $_SESSION['cart'][$key]["num"]   += intval($val['num']); 
                } 
              
                else 
                { 


                    $_SESSION['cart'][$key]  = $data[$key]; 
                    $_SESSION['cart'][$key]["name"]  = $val['name']; 
                    $_SESSION['cart'][$key]["price"] = $val['price']; 
                    $_SESSION['cart'][$key]["count"] = floatval($val['price'])*intval($val['num']); 
                    $_SESSION['cart'][$key]["num"]   = intval($val['num']); 
                } 
            } 
        } */
    } 
 
    function _isExists($id) 
    { 
        if(isset($_SESSION['cart'][$id])&&!empty($_SESSION['cart'][$id])&&array_key_exists($id,$_SESSION['cart'])) 
        { 
            Return true; 
        } 
        else 

        { 
            Return false; 
        } 
    } 
 
    function modItem($id,$num) 
    { 
        $arr = $this->getItems($id); 
      
        if($this->_isExists($id)) 

        { 
            $_SESSION['cart'][$id]["count"] = intval($arr['price'])*intval($num); 
            $_SESSION['cart'][$id]["num"]   = intval($num); 
        } 
    } 

    function getItems($id=null) 
    { 
        if(isset($_SESSION['cart'])) 
        { 


            if($id==null) 
            { 
                Return $_SESSION['cart']; 
            } 
            else 
            { 
                Return $_SESSION['cart'][$id]; 
            } 
        } 
    } 
  
    function emptyItem($id) 
    { 
 
	
	
       if($id==null) 
        { 
            unset($_SESSION['cart']);
			 
        } 
        else 
        { 
            unset($_SESSION['cart'][$id]); 
        } 
    } 

    function sum() 
    { 
        $total = 0; 
        if(isset($_SESSION['cart'])&&!empty($_SESSION['cart'])) 
        { 
            foreach($_SESSION['cart'] as $key=>$val) 
            { 
                $total += $val['count']; 
            } 
        } 
        Return $total; 
    } 
} 
?>